#!/bin/sh
#
# Run a backup of generated data and check if the soft quota limits are respected
#
#
TestName="allowed-scriptdir-test"
JobName=BackupClient1
. scripts/functions

scripts/cleanup
scripts/copy-test-confs


# create the run before job script
echo "#!/bin/sh
echo allowed script dir: runbeforejob
" > $working/runbeforejob.sh
chmod +x $working/runbeforejob.sh

cp -f $working/runbeforejob.sh $tmp/

rm -f bin/susan-dir.conf
/bin/cp -f ${rconfigs}/${TestName}/susan-dir.conf.allowed-scriptdir-test bin/susan-dir.conf
/bin/cp -f ${rconfigs}/${TestName}/susan-fd.conf.allowed-scriptdir-test bin/susan-fd.conf

# create test data
dd if=/dev/zero of=${cwd}/tmp/testdata bs=400k count=1

echo "${cwd}/tmp/testdata" >${cwd}/tmp/file-list
start_test

# we make the following tests:

#@$out /dev/null
cat >${cwd}/tmp/bconcmds <<END_OF_DATA
messages
label storage=File volume=TestVolume001
@$out ${cwd}/tmp/log1.out
run job=$JobName Level=Full yes
wait
messages

END_OF_DATA

run_susan
check_for_zombie_jobs storage=File
stop_susan

# check if first "run before job" worked:
grep "ClientBeforeJob: allowed script dir: runbeforejob" ${tmp}/log1.out 2>&1 >/dev/null
if test $? -eq 0; then
   print_debug "Script in Allowed Script Dir worked: OK"
else
   estat=1
fi

# check if second run before job failes because of Allowed Script Dir:
grep "Error: Runscript: run ClientBeforeJob.*could not execute, not in one of the allowed scripts dirs" ${tmp}/log1.out 2>&1 >/dev/null
if test $? -eq 0; then
   print_debug "Script NOT in Allowed Script Dir failed: OK"
else
   estat=2
fi

end_test
